package com.atguigu.stgy.admin.service.impl;

import com.atguigu.stgy.admin.mapper.FeeValueMapper;
import com.atguigu.stgy.admin.service.FeeKeyService;
import com.atguigu.stgy.model.entity.FeeValue;
import com.atguigu.stgy.admin.controller.FeeKeyVo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.stgy.model.entity.FeeKey;
import com.atguigu.stgy.admin.mapper.FeeKeyMapper;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class FeeKeyServiceImpl extends ServiceImpl<FeeKeyMapper, FeeKey> implements FeeKeyService {

    @Resource
    FeeValueMapper feeValueMapper;

    @Override
    public List<FeeKeyVo> listFeeKeyVos() {
        List<FeeKey> feeKeys = this.list();

        List<FeeValue> feeValues = feeValueMapper.selectList(null);


        List<FeeKeyVo> feeKeyVos =feeKeys.stream().map(feeKey -> {
            FeeKeyVo feeKeyVo = new FeeKeyVo();
            BeanUtils.copyProperties(feeKey,feeKeyVo);
        List<FeeValue>  Values = feeValues.stream().filter(feeValue -> feeValue.getFeeKeyId().equals(feeKeyVo.getId()))
                    .collect(Collectors.toList());
            feeKeyVo.setFeeValueList(Values);
            return feeKeyVo;
        }).collect(Collectors.toList());
        return feeKeyVos;
    }
}
